package org.itstack;



import org.itstack.model.Order;
import org.itstack.model.vo.TreeNodeLink;

import java.util.List;

public abstract class BaseOrderLogic implements OrderLogicFilter {
    
    @Override
    public Long filter(String matterValue, List<TreeNodeLink> treeNodeLinkList) {
        for (TreeNodeLink nodeLink : treeNodeLinkList) {
            if (decisionLogic(matterValue, nodeLink)) {
                return nodeLink.getNodeIdTo();
            }
        }
        return 0L;
    }
    
    @Override
    public abstract String matterValue(Order order);
    
    private boolean decisionLogic(String matterValue, TreeNodeLink nodeLink) {
        switch (nodeLink.getRuleLimitType()) {
            case 1: // 等于
                return matterValue.equals(nodeLink.getRuleLimitValue());
            case 2: // 大于
                return Double.parseDouble(matterValue) > Double.parseDouble(nodeLink.getRuleLimitValue());
            case 3: // 小于
                return Double.parseDouble(matterValue) < Double.parseDouble(nodeLink.getRuleLimitValue());
            case 4: // 小于等于
                return Double.parseDouble(matterValue) <= Double.parseDouble(nodeLink.getRuleLimitValue());
            case 5: // 大于等于
                return Double.parseDouble(matterValue) >= Double.parseDouble(nodeLink.getRuleLimitValue());
            case 6: // 枚举范围
                return nodeLink.getRuleLimitValue().contains(matterValue);
            default:
                return false;
        }
    }
}
